package com.taglab.chic.taglib.analytics;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.springframework.util.Assert;

public class Transaction {

  private String orderId;
  private String affiliation;
  private String total;
  private String tax;
  private String shipping;
  private String city;
  private String state;
  private String country;

  private Set<Item> items = new HashSet<Item>();
  
  public Transaction(String orderId, String total) {
    Assert.hasLength(orderId, "Order ID must be set");
    Assert.hasLength(total, "Total must be set");    
    this.orderId = orderId;
    this.total = total;
  }
  
  public String getOrderId() {
    return orderId;
  }

  public String getAffiliation() {
    return affiliation;
  }

  public void setAffiliation(String affiliation) {
    this.affiliation = affiliation;
  }

  public String getTotal() {
    // XXX calculate total from items if not set...
    return total;
  }

  public void setTotal(String total) {
    this.total = total;
  }

  public String getTax() {
    return tax;
  }

  public void setTax(String tax) {
    this.tax = tax;
  }

  public String getShipping() {
    return shipping;
  }

  public void setShipping(String shipping) {
    this.shipping = shipping;
  }

  public String getCity() {
    return city;
  }

  public void setCity(String city) {
    this.city = city;
  }

  public String getState() {
    return state;
  }

  public void setState(String state) {
    this.state = state;
  }

  public String getCountry() {
    return country;
  }

  public void setCountry(String country) {
    this.country = country;
  }
  
  public void addItem(Item item) {
    Assert.notNull(item, "item cannot be null");
    items.add(item);
  }
  
  public Set<Item> getItems() {
    return Collections.unmodifiableSet(items);
  }
  
}
